#encoding=utf-8
from fixture import db


# def get_verify_code(mobile):
#     verify_code = db.execute("SELECT content FROM sms_log where mobile = %s ",
#                            params=mobile)
#     return int(verify_code['content'][16:20])

def get_response(captcha_hash):
    response = db.execute("SELECT response FROM captcha_captchastore where hashkey = %s ",
                          params=captcha_hash)
    return response['response']


def clear_user(mobile):
    db.execute("DELETE FROM auth_user where username = %s ",
               params=mobile)


def select_user(mobile):
    username = db.execute("SELECT username FROM auth_user where username = %s ",
                          params=mobile)
    return username['username']

def update_user_password(mobile):
    db.execute("UPDATE auth_user SET password='pbkdf2_sha256$30000$vsiKd0zqebop$YGXkFH/1mlSvRIeC7Kcv2F3BXhrvldd4Bb6ddRJWD+c=' WHERE username = %s ",
                          params=mobile)

def select_car_apply(mobile):
    car_apply_details = db.execute("SELECT car_brand,car_price FROM applicant_info where mobile = %s",params=mobile)
    return car_apply_details

def clear_car_apply(mobile):
    db.execute("DELETE FROM applicant_info where mobile = %s",params=mobile)

def select_user_info(mobile):
    user_info = db.execute("SELECT gender,real_name FROM user_profile where mobile = %s",params=mobile)
    return user_info

def select_contract_status(mobile):
    contract_status = db.execute("SELECT status FROM contract where mobile = %s",params=mobile)
    return contract_status

def select_car_plate_number(mobile):
    contract_id  = db.execute("SELECT id FROM contract where mobile = %s",params=mobile)['id']
    car_plate_number = db.execute("SELECT plate_number FROM car where contract_id = %s",params=contract_id)
    return car_plate_number['plate_number']

def select_car_trade_time(mobile):
    contract_id = db.execute("SELECT id FROM contract where mobile = %s", params=mobile)
    trade_time = db.execute("SELECT start_date,end_date FROM trade where contract_id = %s", params=contract_id['id'])
    return trade_time

def update_rent_order():
    db.execute("update rent_order set rent_status = 'CANCEL' order by created_time desc limit 1")